#include "opendialogimpl.h"
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QString>
#include <cmath>
//
OpenDialogImpl::OpenDialogImpl( QWidget * parent, Qt::WFlags f) 
	: QDialog(parent, f)
{
	setupUi(this);
}
//

void OpenDialogImpl::on_browseButton_clicked()
{
	QString fileName = QFileDialog::getOpenFileName(this,trUtf8("Otwórz plik"), "/home", tr("Wszystkie pliki (*)"));
	if( fileName != "" ) fileEdit->setText(fileName);
}

void OpenDialogImpl::on_buttonBox_accepted()
{
	if( fileEdit->text() == "" )
	{
		QMessageBox::warning( this, trUtf8("Ostrzeżenie"), trUtf8("Musisz wybrać plik!") );
	}
	else if( !QFile::exists( fileEdit->text() ) )
	{
		QMessageBox::warning( this, trUtf8("Ostrzeżenie"), trUtf8("Wybrany plik nie istnieje!") );
	}
	else
		accept();
}

DataFile * OpenDialogImpl::getDataFile(QObject * parent)
{
	DataFile * f = new DataFile( parent );
	f->setFileName( fileEdit->text() );
	f->setChannels( channels->value() );
	f->setDataType( (DataFile::DataTypes)dataType->currentIndex() );
	f->setSampleRate( sampleRate->value() * pow( 1000, unit->currentIndex() ) );
	f->setByteOrder( (QDataStream::ByteOrder)byteOrder->currentIndex() );
	return f;
}

